var app = getApp();

Page({
    data: {
        _card_info: [],
        glo_is_load: !1,
        btn_disabled: !1,
        submitIsLoading: !1,
        yzm_btn_disabled: !0,
        showView: !1,
        yzm_all_time: 60,
        _mobile: "",
        phone_yzm_code: "",
        img_index: 0,
        image_list1: [],
        tempFilePaths: [],
        cardid: 0,
        img_count_limit: 12,
        this_img_i: 0,
        QR_code: "",
        avatar: "",
        postImg: "",
        avaterImg: "",
        uploadimgArr: [],
        this_img_max: 0
    },
    open: function() {
        this.setData({
            condition: !this.data.condition
        });
    },
    onLoad: function(a) {
        var t = this;
        app.globalData.hasLogin ? t.setData({
            userInfo: app.globalData.userInfo
        }) : app.util.getUserInfo(function(a) {
            app.globalData.hasLogin = !0, t.setData({
                userInfo: a
            }), app.globalData.userInfo = a;
        });
        var e = a.cardid;
        t.setData({
            cardId: e
        }), 0 < e && app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card",
                cardid: e
            },
            success: function(a) {
                0 == a.data.errno ? t.setData({
                    _card_info: a.data.data,
                    cardid: a.data.data.id,
                    tempFilePaths: a.data.data.imgs,
                    QR_code: a.data.data.QR_code,
                    uploadimgArr: a.data.data.imgs
                }) : t.setData({
                    avater: t.data.userInfo.memberInfo.avatar
                });
            }
        });
    },
    onShow: function() {
        var a = this, t = a.data.cardId;
        a.setData({
            yzm_all_time: 60,
            cardid: t,
            avater: a.data.userInfo.memberInfo.avatar
        });
    },
    imgDel: function(a) {
        var t = this, e = a.currentTarget.id, i = t.data.tempFilePaths, s = t.data.uploadimgArr;
        i.splice(e, 1), s.splice(e, 1), t.setData({
            tempFilePaths: i,
            uploadimgArr: s
        });
    },
    previewImage: function(a) {
        wx.previewImage({
            current: a.target.dataset.url,
            urls: [ a.target.dataset.url ]
        });
    },
    upload_img: function(s, o) {
        s.setData({
            hidden: !1
        });
        var a = app.util.url("entry/wxapp/WxUpload");
        wx.uploadFile({
            url: a + "m=bbyscm_card",
            filePath: o,
            name: "file",
            success: function(a) {
                console.log("判断是否上传成功", a);
                var t = a.data;
                if ("string" == typeof t && (t = JSON.parse(t.trim())), 0 == t.errno) {
                    var e = new Array(), i = new Array();
                    (i = s.data.uploadimgArr).push(t.data), (e = s.data.tempFilePaths).push(o), s.setData({
                        uploadimgArr: i,
                        tempFilePaths: e
                    }), s.data.img_index = s.data.img_index + 1, s.data.img_index < s.data.image_list1.length ? s.upload_img(s, "" + s.data.image_list1[s.data.img_index]) : s.setData({
                        hidden: !0
                    });
                } else s.setData({
                    hidden: !0
                });
            },
            fail: function(a) {
                s.setData({
                    hidden: !0
                });
            }
        });
    },
    addimg: function() {
        var e = this;
        e.data.tempFilePaths.length < 12 ? wx.chooseImage({
            count: 12 - e.data.tempFilePaths.length,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                e.data.image_list1 = new Array();
                for (var t = 0; t < a.tempFilePaths.length; t++) e.data.image_list1.push(a.tempFilePaths[t]);
                e.upload_img(e, "" + e.data.image_list1[0]);
            },
            fail: function() {
                wx.showToast({
                    title: "选取失败",
                    icon: "success",
                    duration: 2e3
                });
            }
        }) : wx.showToast({
            title: "当前最多只能选择9张图片",
            icon: "success",
            duration: 1e4
        });
    },
    addWeixin: function() {
        var o = this;
        o.data.QR_code;
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var s = a.tempFilePaths;
                wx.showToast({
                    title: "正在上传...",
                    icon: "loading",
                    duration: 1e4
                });
                var t = app.util.url("entry/wxapp/WxUpload");
                wx.uploadFile({
                    url: t + "m=bbyscm_card",
                    filePath: s[0],
                    name: "file",
                    formData: {},
                    success: function(a) {
                        var t = "", e = "", i = a.data;
                        "string" == typeof i && (i = JSON.parse(i.trim())), 0 == i.errno ? (t = s[0], e = i.data, 
                        o.setData({
                            QR_code: t,
                            postImg: e
                        })) : wx.showToast({
                            title: i.message,
                            icon: "success",
                            duration: 2e3
                        });
                    },
                    complete: function() {
                        wx.hideToast();
                    }
                });
            }
        });
    },
    postCard: function(a) {
        var t = this;
        t.setData({
            btn_disabled: !0,
            submitIsLoading: !0
        }), JSON.stringify(a.detail.value);
        var e = a.detail.formId, i = t.data.cardid, s = t.data.uploadimgArr, o = t.data.postImg;
        s = s.join("|"), wx.showToast({
            title: "提交中...",
            icon: "loading",
            duration: 1e4
        }), app.util.request({
            url: "entry/wxapp/PostCardImgs",
            data: {
                m: "bbyscm_card",
                form_id: e,
                cardid: i,
                QR_code: o,
                imgs: s
            },
            method: "POST",
            success: function(a) {
                0 == a.data.errno ? wx.showModal({
                    title: "提示",
                    content: "提交成功",
                    showCancel: !1,
                    success: function(a) {
                        wx.navigateBack();
                    }
                }) : wx.showModal({
                    title: "提示",
                    content: a.data.message,
                    showCancel: !1,
                    success: function(a) {
                        a.confirm;
                    }
                });
            },
            fail: function(a) {
                wx.showModal({
                    title: "提示",
                    content: a.data.message,
                    showCancel: !1,
                    success: function(a) {
                        a.confirm;
                    }
                });
            },
            complete: function() {
                wx.hideToast();
            }
        });
    }
});